package com.cf.expensetracker;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;
import com.cf.expensetracker.command.*;

import java.time.LocalDate;
import java.util.List;

/**
 * Copyright(C) 2025- com.cf
 * FileName:    App
 * Author:      cf
 * Date:        2025/1/17 21:48
 * Description:
 */
public class App {



    public static void main(String[] args) {

        AddCmd addCmd = new AddCmd();
        ListCmd listCmd = new ListCmd();
        SummaryCmd summaryCmd = new SummaryCmd();
        DeleteCmd deleteCmd = new DeleteCmd();
        UpdateCmd updateCmd = new UpdateCmd();
        ExportCmd exportCmd = new ExportCmd();
        BudgetCmd budgetCmd = new BudgetCmd();

        JCommander jCommander = JCommander.newBuilder()
                .programName("expense-tracker")
                .addCommand("add", addCmd)
                .addCommand("list", listCmd)
                .addCommand("delete", deleteCmd)
                .addCommand("summary", summaryCmd)
                .addCommand("update", updateCmd)
                .addCommand("export", exportCmd)
                .addCommand("budget", budgetCmd)
                .build();

        try {
            jCommander.parse(args);
            String parsedCommand = jCommander.getParsedCommand();
            switch (parsedCommand) {
                case "add":
                    HandleCmd.handle(addCmd);
                    break;
                case "list":
                    HandleCmd.handle(listCmd);
                    break;
                case "delete":
                    HandleCmd.handle(deleteCmd);
                    break;
                case "summary":
                    HandleCmd.handle(summaryCmd);
                    break;
                case "update":
                    HandleCmd.handle(updateCmd);
                    break;
                case "export":
                    HandleCmd.handle(exportCmd);
                    break;
                case "budget":
                    HandleCmd.handle(budgetCmd);
                    break;
                default:
                    System.out.println("Unknown command");
                    jCommander.usage();
                    break;
            }

        } catch (ParameterException e) {
            System.err.println("Error parsing command line: " + e.getMessage());
        }
    }
}
